﻿@model Bonobo.Git.Server.Models.RepositoryDetailModel
@{
    Layout = "~/Views/Repository/_RepositoryLayout.cshtml";
    ViewBag.Title = Resources.Repository_Detail_Title;

    string serverAddress = System.Configuration.ConfigurationManager.AppSettings["GitServerPath"]
                        ?? string.Format("{0}://{1}{2}{3}/", 
                                            Request.Url.Scheme, 
                                            Request.Url.Host, 
                                            (Request.Url.IsDefaultPort ? "" : (":" + Request.Url.Port)),
                                            Request.ApplicationPath == "/" ? "" : Request.ApplicationPath
                                        );
}
@if (Model != null)
{
    <div class="pure-form pure-form-aligned detail">
        <fieldset>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Name)
                @Model.Name
                @switch (Model.Status)
                {
                    case RepositoryDetailStatus.Valid:
                        break;
                    case RepositoryDetailStatus.Missing:
                        <span class="status">(Missing)</span>
                        break;
                    case RepositoryDetailStatus.Unknown:
                    default:
                    <span class="status">(Status Unknown)</span>
                        break;
                }
            </div>
            <div class="pure-control-group">
                <label>@Resources.Repository_Detail_Location</label>
                @String.Concat(serverAddress, Model.Name, ".git")
            </div>

            @if (User.Identity.IsAuthenticated){
                <div class="pure-control-group">
                    <label>
                        @Resources.Repository_Detail_Location_Personal
                    </label>

                    @String.Concat(serverAddress.Replace("://", "://" + User.Identity.Name + "@"), Model.Name, ".git")
                </div>
            }

            <div class="pure-control-group">
                @Html.LabelFor(m => m.Group)
                @Model.Group
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Description)
                @Model.Description
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.AllowAnonymous)
                @if (Model.AllowAnonymous)
                {
                    @Resources.Repository_Detail_Yes
                }
                else
                {
                    @Resources.Repository_Detail_No
                }
            </div>
            @if (AppSettings.IsPushAuditEnabled) {
            <div class="pure-control-group">
                @Html.LabelFor(m => m.AuditPushUser)
                @if (Model.AuditPushUser)
                {
                    @Resources.Repository_Detail_Yes
                }
                else
                {
                    @Resources.Repository_Detail_No
                }
            </div>
            }
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Users)
                @for (int i = 0; i < Model.Users.Length; i++)
                {
                    @Html.ActionLink(@Model.Users[i], "Detail", "Account", new { id = UsernameUrl.Encode(@Model.Users[i]) }, null)
                    if (i + 1 != Model.Users.Length)
                    {
                        <text>, </text>
                    }
                }
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Administrators)
                @for (int i = 0; i < Model.Administrators.Length; i++)
                {
                    @Html.ActionLink(@Model.Administrators[i], "Detail", "Account", new { id = UsernameUrl.Encode(@Model.Administrators[i]) }, null)
                    if (i + 1 != Model.Administrators.Length)
                    {
                        <text>, </text>
                    }
                }
            </div>
            <div class="pure-control-group">
                @Html.LabelFor(m => m.Teams)
                @for (int i = 0; i < Model.Teams.Length; i++)
                {
                    @Html.ActionLink(@Model.Teams[i], "Detail", "Team", new { id = @Model.Teams[i] }, null)
                    if (i + 1 != Model.Teams.Length)
                    {
                        <text>, </text>
                    }
                }
            </div>
            <div class="pure-controls">
                <a class="pure-button" href="@Url.Action("Index")"><i class="fa fa-long-arrow-left"></i> @Resources.Repository_Detail_Back</a>
                @if (Model.IsCurrentUserAdministrator)
                {
                    <a class="pure-button" href="@Url.Action("Edit", new { id = Model.Name })"><i class="fa fa-pencil-square-o"></i> @Resources.Repository_Detail_Edit</a>
                    <a class="pure-button" href="@Url.Action("Delete", new { id = Model.Name })"><i class="fa fa-trash-o"></i> @Resources.Repository_Detail_Delete</a>
                }
            </div>
        </fieldset>
    </div>
}
